import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEField } from '../defield/ipsdefield';
import { IPSDEDataSet } from '../ds/ipsdedata-set';
import { IPSDENotify } from './ipsdenotify';
import { IPSDENotifyTarget } from './ipsdenotify-target';
import { IPSSysMsgQueue } from '../../msg/ipssys-msg-queue';
import { IPSSysMsgTempl } from '../../msg/ipssys-msg-templ';
import { IPSSysSFPlugin } from '../../res/ipssys-sfplugin';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDENotifyImpl extends PSModelObjectImpl implements IPSDENotify, IPSModelSortable {
  protected begintimepsdefield: IPSDEField | null = null;

  getBeginTimePSDEField(): IPSDEField | null {
    if (this.begintimepsdefield != null) return this.begintimepsdefield;
    const value = this.M.getBeginTimePSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.begintimepsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.begintimepsdefield;
  }

  get beginTimePSDEField(): IPSDEField | null {
    return this.getBeginTimePSDEField();
  }

  getBeginTimePSDEFieldMust(): IPSDEField {
    const value = this.getBeginTimePSDEField();
    if (value == null) {
      throw new Error('未指定开始时间值存储属性');
    }
    return value;
  }

  get checkTimer(): number {
    return this.M.checkTimer != null ? this.M.checkTimer : 0;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get customCond(): string {
    return this.M.customCond;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  protected endtimepsdefield: IPSDEField | null = null;

  getEndTimePSDEField(): IPSDEField | null {
    if (this.endtimepsdefield != null) return this.endtimepsdefield;
    const value = this.M.getEndTimePSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.endtimepsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.endtimepsdefield;
  }

  get endTimePSDEField(): IPSDEField | null {
    return this.getEndTimePSDEField();
  }

  getEndTimePSDEFieldMust(): IPSDEField {
    const value = this.getEndTimePSDEField();
    if (value == null) {
      throw new Error('未指定结束时间值存储属性');
    }
    return value;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get memo(): string {
    return this.M.memo;
  }

  get msgType(): 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 {
    return this.M.msgType;
  }

  get name(): string {
    return this.M.name;
  }

  get notifyEnd(): number {
    return this.M.notifyEnd != null ? this.M.notifyEnd : 0;
  }

  get notifyStart(): number {
    return this.M.notifyStart != null ? this.M.notifyStart : 0;
  }

  get notifyTag(): string {
    return this.M.notifyTag;
  }

  get notifyTag2(): string {
    return this.M.notifyTag2;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdedataset: IPSDEDataSet | null = null;

  getPSDEDataSet(): IPSDEDataSet | null {
    if (this.psdedataset != null) return this.psdedataset;
    const value = this.M.getPSDEDataSet;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdedataset = ipsdataentity.findPSDEDataSet(value);
    }
    return this.psdedataset;
  }

  get psDEDataSet(): IPSDEDataSet | null {
    return this.getPSDEDataSet();
  }

  getPSDEDataSetMust(): IPSDEDataSet {
    const value = this.getPSDEDataSet();
    if (value == null) {
      throw new Error('未指定数据集');
    }
    return value;
  }

  protected psdenotifytars: IPSDENotifyTarget[] | null = null;

  getPSDENotifyTargets(): IPSDENotifyTarget[] | null {
    if (this.psdenotifytars == null) {
      this.psdenotifytars = this.fillChildListModel(this.M.getPSDENotifyTargets, 'dataentity.notify.IPSDENotifyTarget') as IPSDENotifyTarget[];
    }
    return this.psdenotifytars;
  }

  get psDENotifyTargets(): IPSDENotifyTarget[] | null {
    return this.getPSDENotifyTargets();
  }

  findPSDENotifyTarget(objKey: any): IPSDENotifyTarget | null {
    return this.getPSModel5('dataentity.notify.IPSDENotifyTarget', this.getPSDENotifyTargets(), objKey) as IPSDENotifyTarget;
  }

  protected pssysmsgqueue: IPSSysMsgQueue | null = null;

  getPSSysMsgQueue(): IPSSysMsgQueue | null {
    if (this.pssysmsgqueue != null) return this.pssysmsgqueue;
    const value = this.M.getPSSysMsgQueue;
    if (value == null) {
      return null;
    }
    this.pssysmsgqueue = this.getPSModel4('msg.IPSSysMsgQueue', value, 'getPSSysMsgQueue') as IPSSysMsgQueue;
    return this.pssysmsgqueue;
  }

  get psSysMsgQueue(): IPSSysMsgQueue | null {
    return this.getPSSysMsgQueue();
  }

  getPSSysMsgQueueMust(): IPSSysMsgQueue {
    const value = this.getPSSysMsgQueue();
    if (value == null) {
      throw new Error('未指定系统消息队列');
    }
    return value;
  }

  protected pssysmsgtempl: IPSSysMsgTempl | null = null;

  getPSSysMsgTempl(): IPSSysMsgTempl | null {
    if (this.pssysmsgtempl != null) return this.pssysmsgtempl;
    const value = this.M.getPSSysMsgTempl;
    if (value == null) {
      return null;
    }
    this.pssysmsgtempl = this.getPSModel4('msg.IPSSysMsgTempl', value, 'getPSSysMsgTempl') as IPSSysMsgTempl;
    return this.pssysmsgtempl;
  }

  get psSysMsgTempl(): IPSSysMsgTempl | null {
    return this.getPSSysMsgTempl();
  }

  getPSSysMsgTemplMust(): IPSSysMsgTempl {
    const value = this.getPSSysMsgTempl();
    if (value == null) {
      throw new Error('未指定系统消息模板');
    }
    return value;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  get taskMode(): 0 | 1 {
    return this.M.taskMode;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get timerMode(): boolean {
    return this.M.timerMode != null ? this.M.timerMode : false;
  }

  get cls(): string {
    return 'PSDENotifyImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.notify.IPSDENotify') return true;
    return super.instanceof(cls);
  }
}
